from datetime import datetime
from typing import Any
from pydantic import BaseModel, Field


# ---------------------- 定义模型 ----------------------
class Additional(BaseModel):
    """额外信息"""
    time: str
    trace_id: str

class PageModel(BaseModel):
    page: int
    limit: int


class HttpResponse(BaseModel):
    """http统一响应"""
    code: int = Field(default=200)  # 响应码
    message: str = Field(default="处理成功")  # 响应信息
    data : Any = Field(default=None)
    timestamp: str  # 额外信息


def ResponseSuccess(resp: Any) -> HttpResponse:
    """成功响应"""
    currentTime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    return HttpResponse(
        data=resp,
        timestamp=currentTime,
    )


def ResponseFail(msg: str, code: int = -1) -> HttpResponse:
    """响应失败"""
    currentTime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    return HttpResponse(
        code=code,
        message=msg,
        timestamp=currentTime,
    )
